from threading import Thread

class ThreadCPU(Thread):
    
    def __init__(self, aCPU, aSched):
        Thread.__init__(self)
        self.myCPU = aCPU
        self.myScheduler = aSched
        
    def run(self):
        while(True):
            if (self.myCPU.getFreedom() and (not self.myCPU.readyQueue.empty())): 
                self.myCPU.setQuantumPolicy()
                self.myCPU.setQuantum()
                
                if(self.myCPU.getQuantumPolicy()):
                    x = self.myScheduler.nextPCB2()
                    if (not x.isFinished()): 
                        self.myCPU.executePCB2(x)
                else:
                    x = self.myScheduler.nextPCB()
                    if (not x.isFinished()): 
                        self.myCPU.executePCB(x)